package com.expect.admin.busmanagement.data.dataobject;

import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.GenericGenerator;

import com.expect.admin.busmanagement.service.vo.BusVo;
import com.expect.admin.data.dataobject.Attachment;
import com.expect.admin.data.dataobject.Lcrzb;
import com.expect.admin.data.dataobject.User;
import com.expect.admin.utils.DateUtil;
import com.expect.admin.utils.StringUtil;

@Entity
@Table(name = "s_bus_inf")
public class Bus {
	private String id;
	private String bh;//车辆编号
	
	private String busNo;//车牌号
	private User userName;//驾驶员
	private Date applicationDate;//申请日期
	private String applicationMoney;//申请金额
	private String paymentWay;//支付方式
	private String applicationReason;//申请事由
	private String applicationStatement;//申请状态
	private String applicationClassify;//申请分类
	private String applicationOption;//申请选项：加油、维修、保养
	private String lcbs;//流程标识
	private String isDeleted;//是否已经删除（采用软删除，只标识，不删除）
	private String isReturned;//是否退回（Y是退回，N是未退回）
	private Set<Attachment> attachments;//附件
	private String sbd;//申办单名称
	private Set<Lcrzb> lcrzSet = new HashSet<>();//流程日志
	
	public Bus(){
		
	}
	
	public Bus(BusVo busVo){
		this.id = busVo.getId();
		this.bh = busVo.getBh();
		this.busNo = busVo.getBusNo();
		if(!StringUtil.isBlank(busVo.getApplicationDate())){
			this.applicationDate = new Date();
		}else{
			this.applicationDate = DateUtil.parse(busVo.getApplicationDate(), DateUtil.fullFormat);
		}
		this.applicationMoney = busVo.getApplicationMoney();
		this.paymentWay = busVo.getPaymentWay();
		this.applicationReason = busVo.getApplicationReason();
		this.applicationStatement = busVo.getApplicationStatement();
		this.applicationClassify = busVo.getApplicationClassify();
		this.applicationOption = busVo.getApplicationOption();
		this.lcbs = busVo.getLcbs();
		if(!StringUtil.isBlank(busVo.getSbd())){
			this.sbd = busVo.getSbd();
		}
	}
	
	@Id
	@GeneratedValue(generator = "uuid")
	@GenericGenerator(name = "uuid", strategy = "uuid")
	@Column(name = "id", nullable = false, unique = true, length = 32)
	public String getId(){
		return id;
	}
	public void setId(String id){
		this.id = id;
	}
	
	@Column(name = "bh", length = 20)
	public String getBh(){
		return bh;
	}
	public void setBh(String bh){
		this.bh = bh;
	}
	
	@Column(name = "busNo", length = 7)
	public String getBusNo() {
		return busNo;
	}
	public void setBusNo(String busNo){
		this.busNo = busNo;
	}
	
	@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
	@JoinColumn(name = "user_id")
	public User getUserName() {
		return userName;
	}
	public void setUserName(User userName){
		this.userName = userName;
	}
	
	@Column(name = "applicationDate")
	public Date getApplicationDate(){
		return applicationDate;
	}
	public void setApplicationDate(Date applicationDate){
		this.applicationDate =applicationDate;
	}
	
	@Column(name = "applicationMoney",length = 100)
	public String getApplicationMoney(){
		return applicationMoney;
	}
	public void setApplicationMoney(String applicationMoney){
		this.applicationMoney = applicationMoney;
	}
	
	@Column(name = "paymentWay",length = 100)
	public String getPaymentWay(){
		return paymentWay;
	}
	public void setPaymentWay(String paymentWay){
		this.paymentWay = paymentWay;
	}
	
	@Column(name = "applicationReason",length = 300)
	public String getApplicationReason(){
		return applicationReason;
	}
	public void setApplicationReason(String applicationReason){
		this.applicationReason = applicationReason;
	}
	
	@Column(name = "applicationStatement",length = 200)
	public String getApplicationStatement(){
		return applicationStatement;
	}
	public void setApplicationStatement(String applicationStatement){
		this.applicationStatement = applicationStatement;
	}
	
	@Column(name = "applicationClassify", length = 20)
	public String getApplicationClassify(){
		return applicationClassify;
	}
	public void setApplicationClassify(String applicationClassify){
		this.applicationClassify = applicationClassify;
	}
	
	@Column(name = "applicationOption", length = 20)
	public String getApplicationOption(){
		return applicationOption;
	}
	public void setApplicationOption(String applicationOption){
		this.applicationOption = applicationOption;
	}
	
	@Column(name = "lcbs",length = 32)
	public String getLcbs(){
		return lcbs;
	}
	public void setLcbs(String lcbs){
		this.lcbs = lcbs;
	}
	
	@Column(name = "isDeleted",length = 2)
	public String getIsDeleted(){
		return isDeleted;
	}
	public void setIsDeleted(String isDeleted){
		this.isDeleted = isDeleted;
	}
	
	@Column(name = "isReturned",length = 2)
	public String getIsReturned(){
		return isReturned;
	}
	public void setIsReturned(String isReturned){
		this.isReturned = isReturned;
	}
	
	@Column(name = "sbd",length = 50)
	public String getSbd(){
		return sbd;
	}
	public void setSbd(String sbd){
		this.sbd = sbd;
	}
	
	@ManyToMany(cascade = CascadeType.REFRESH,fetch = FetchType.LAZY)
	@JoinTable(name = "s_bus_attachment", joinColumns = @JoinColumn(name = "bus_id"), inverseJoinColumns = @JoinColumn(name = "attachment_id"))
	public Set<Attachment> getAttachments(){
		return attachments;
	}
	public void setAttachments(Set<Attachment> attachments){
		this.attachments = attachments;
	}
	
	@ManyToMany(cascade = CascadeType.REFRESH,fetch = FetchType.LAZY)
	@JoinTable(name = "s_bus_lcrzb",joinColumns = @JoinColumn(name = "bus_id"),inverseJoinColumns = @JoinColumn(name = "lcrzb_id"))
	public Set<Lcrzb> getLcrzSet(){
		return lcrzSet;
	}
	public void setLcrzSet(Set<Lcrzb> lcrzSet){
		this.lcrzSet = lcrzSet;
	}
}
